import CryptoJS from 'crypto-js'

let key = 'samQCBLog'
let iv = 'qc@2023'

key = CryptoJS.enc.Utf8.parse(key)
iv = CryptoJS.enc.Utf8.parse(iv)

// DES 加密
const encryptDES = function(str) {
  let encrypted = CryptoJS.DES.encrypt(str, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  // 转换为字符串
  encrypted = encrypted.toString()
  return encrypted
}

// DES 解密
const decryptDES = function (encrypted) {
  let decrypted = CryptoJS.DES.decrypt(encrypted, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  // 转换为 utf8 字符串
  decrypted = CryptoJS.enc.Utf8.stringify(decrypted)
  return decrypted
}

export { encryptDES, decryptDES }